/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package views;

import controllers.Funciones;
import controllers.Peliculas;
import controllers.Salas;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author kevin_000
 */
public class EditarHorarios extends javax.swing.JFrame {

    /**
     * Creates new form EditarHorarios
     */
    ResultSet rs;
    Salas sala;
    Peliculas pl;
    Funciones funcion;
    
    public EditarHorarios() {
        initComponents();
        sala = new Salas();
        pl = new Peliculas();
        funcion = new Funciones();
        setSize(600, 500);
        setLocationRelativeTo(null);
        try {
            rs = sala.listarSalas();
           while(rs.next()){
                cmbSalas.addItem(rs.getString("idSalas"));
            }
        } catch (SQLException ex) {
            Logger.getLogger(EliminarSala.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            rs = pl.listPeliculas();
           while(rs.next()){
                cmbPeliculas.addItem(rs.getString("titulo"));
            }
        } catch (SQLException ex) {
            Logger.getLogger(EliminarSala.class.getName()).log(Level.SEVERE, null, ex);
        }
        btnAceptar.setVisible(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        cmbPeliculas = new javax.swing.JComboBox();
        cmbSalas = new javax.swing.JComboBox();
        jLabel11 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        txtHora = new javax.swing.JTextField();
        btnAceptar = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabel13 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Edicion de los Horarios");
        getContentPane().setLayout(null);

        jLabel3.setFont(new java.awt.Font("Rockwell", 3, 48)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(255, 255, 255));
        jLabel3.setText("Agregar FUNCION");
        getContentPane().add(jLabel3);
        jLabel3.setBounds(80, 20, 590, 50);

        jLabel4.setFont(new java.awt.Font("Rockwell", 1, 30)); // NOI18N
        jLabel4.setForeground(new java.awt.Color(255, 255, 255));
        jLabel4.setText("Numero de Sala");
        getContentPane().add(jLabel4);
        jLabel4.setBounds(20, 170, 240, 40);

        cmbPeliculas.setFont(new java.awt.Font("Rockwell", 1, 18)); // NOI18N
        getContentPane().add(cmbPeliculas);
        cmbPeliculas.setBounds(280, 140, 380, 30);

        cmbSalas.setFont(new java.awt.Font("Rockwell", 1, 18)); // NOI18N
        getContentPane().add(cmbSalas);
        cmbSalas.setBounds(280, 180, 150, 30);

        jLabel11.setFont(new java.awt.Font("Rockwell", 1, 18)); // NOI18N
        jLabel11.setForeground(new java.awt.Color(255, 255, 255));
        jLabel11.setText("(Valor entre 8 y 22)");
        getContentPane().add(jLabel11);
        jLabel11.setBounds(20, 290, 220, 40);

        jLabel10.setFont(new java.awt.Font("Rockwell", 1, 30)); // NOI18N
        jLabel10.setForeground(new java.awt.Color(255, 255, 255));
        jLabel10.setText("Hora Inicio");
        getContentPane().add(jLabel10);
        jLabel10.setBounds(20, 250, 220, 40);
        getContentPane().add(txtHora);
        txtHora.setBounds(300, 260, 40, 30);

        btnAceptar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/Boton 20.png"))); // NOI18N
        btnAceptar.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/Boton 20 Rollover.png"))); // NOI18N
        btnAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAceptarActionPerformed(evt);
            }
        });
        getContentPane().add(btnAceptar);
        btnAceptar.setBounds(120, 370, 180, 60);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/Boton 21.png"))); // NOI18N
        jButton1.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/Boton 21 Rollover.png"))); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1);
        jButton1.setBounds(410, 370, 180, 60);

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/Boton 24.png"))); // NOI18N
        jButton2.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/Boton 24 Rollover.png"))); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton2);
        jButton2.setBounds(410, 240, 170, 60);

        jLabel13.setFont(new java.awt.Font("Rockwell", 1, 30)); // NOI18N
        jLabel13.setForeground(new java.awt.Color(255, 255, 255));
        jLabel13.setText("Pelicula");
        getContentPane().add(jLabel13);
        jLabel13.setBounds(20, 130, 150, 40);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/planets-1920x1080.jpg"))); // NOI18N
        getContentPane().add(jLabel1);
        jLabel1.setBounds(-400, -200, 1920, 730);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAceptarActionPerformed
        try {
            rs = pl.idPeliculas(cmbPeliculas.getSelectedItem().toString());
            String idPelicula = "";
            if(rs.next())
                idPelicula = rs.getString("idPelicula");
            
            funcion.crearFuncion(cmbSalas.getSelectedItem().toString(), idPelicula,Integer.parseInt(txtHora.getText()));
            this.dispose();
        } catch (SQLException ex) {
            Logger.getLogger(EditarHorarios.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btnAceptarActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

        this.dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
       if(Integer.parseInt(txtHora.getText())>=8 && Integer.parseInt(txtHora.getText())<=22)
        {
            if(funcion.checarDisponibilidad(Integer.parseInt(txtHora.getText()), cmbPeliculas.getSelectedItem().toString(), 
                cmbSalas.getSelectedItem().toString())==true){
            JOptionPane.showMessageDialog(null, "Existe disponibilidad");
            btnAceptar.setVisible(true);
        }
      }
    }//GEN-LAST:event_jButton2ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(EditarHorarios.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(EditarHorarios.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(EditarHorarios.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(EditarHorarios.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new EditarHorarios().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAceptar;
    private javax.swing.JComboBox cmbPeliculas;
    private javax.swing.JComboBox cmbSalas;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JTextField txtHora;
    // End of variables declaration//GEN-END:variables
}
